using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Webadmin_Modules_User_GroupPermission : System.Web.UI.UserControl
{
    //----------------------------------------------------------
    public DataRow _SiteOption = null;
    public DataRow _AdminLang = null;
    public string _Act = "";
    private string _SiteNote = "General";
    private string _LangNote = "UserGroup";
    public string _Filter = "";
    public string _Navigator = "";
    public string _ID = "";
    public string _CateID = "";
    private void initSiteLang()
    {
        
        if (!Request.Url.AbsoluteUri.Contains(Session["Page"].ToString()))
        {
            Session["Page"] = Request.Url.AbsoluteUri.Split('?')[0];
        }
        //---------
        Session["Lang"] = Request.QueryString["Lang"] == null ? Session["Lang"] : Request.QueryString["Lang"];
        Session["Lang"] = bzAdminLang.checkLang(Session["Lang"].ToString());
        _SiteOption = new bzSiteOption("SiteAdmin", _SiteNote).SiteOption;
        _AdminLang = new bzAdminLang(Session["Lang"].ToString(), _LangNote).AdminLang;

        this.check(bzCheckAdminUser.View);
        _Act = Request.QueryString["Act"] == null ? "" : Request.QueryString["Act"];
        _ID = Request.QueryString["ID"] == null ? "" : Request.QueryString["ID"];
        _CateID = Request.QueryString["CateID"] == null ? "" : Request.QueryString["CateID"];

        this.loadAction();
    }
    private bool check(int Per)
    {
        if (bzCheckAdminUser.checkUserPermission(Session["AdminUser"].ToString(), Session["AdminLevel"].ToString(), Session["IP"].ToString(), Session["LoginID"].ToString(), Session["GroupUser"].ToString(), Session["Page"].ToString(), Per)) return true;
        Response.Redirect(bzStringClass.AlertPermission);
        return false;
    }
    //----------------------------------------------------------------------------------



    public DataTable _dt = new DataTable();
    private bzUserGroup bz = new bzUserGroup();   
    public AdminFunction_AdminGroupUser AFG = new AdminFunction_AdminGroupUser();
    public dbConnection _DB = new dbConnection();
    protected void Page_Load(object sender, EventArgs e)
    {
        this.initSiteLang();
        
    }
    public DataTable getFunction(string sGroup)
    {
        SqlParameter p = new SqlParameter("@GroupName", sGroup);
        return _DB.getDataTable("SP_getAdminFunction_GroupName", p);
    }
    private void loadAction()
    {
        _dt = _DB.getDataTable("SP_getAdminFunctionGroup");
        this.btnUpdate.Text = _AdminLang["UserGroup_Permission"].ToString();
        _Navigator = _AdminLang["MenuUser"] + bzStringClass.Arrow + _AdminLang["MenuUserGroup"] + bzStringClass.Arrow + _AdminLang["UserGroup_Permission"];
       
    }
   
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        if (this.check(bzCheckAdminUser.Delete))
        {
            string[] functionName = Request.Form["txtFunctionName"].Split(',');
            string[] functionLevel = Request.Form["selLevel"].Split(',');
            if (functionLevel.Length != functionName.Length)
            {
                Response.Write(bzStringClass.addStringAlert(_AdminLang["UserGroup_PermissionFailed"]));
                Response.Write(bzStringClass.redirectClient("UserGroup.aspx?Act=Permission&ID="+_ID));
            }
            AFG.deleteRecord(_ID);
            for (int i = 0; i < functionLevel.Length; i++)
            {
                AFG.insertRecord(functionName[i], _ID, functionLevel[i], AdminFunction_AdminGroupUser.Code);
            }
        }       
    }
    
}
